package com.tank;

public class Shot implements Runnable{
    private int x;
    private int y;
    private int direct;//方向
    private int speed=3;//速度
    private boolean isLive=true;//子弹是否活着(存在)

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }


    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }


    @Override
    public void run() {//射出子弹
        while(true){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //
            switch(direct){
                case 0://上
                    y-=speed;
                    break;
                case 1://右
                    x+=speed;
                    break;
                case 2://下
                    y+=speed;
                    break;
                case 3://左
                    x-=speed;
                    break;
            }
            System.out.println("子弹坐标 "+"x:"+x+"y:"+y);
            if(x<0||y<0||x>1000||y>750){//子弹出界或击中目标
                isLive=false;//子弹销毁
                break;
            }
        }

    }
}
